#include "precomp.h"
#include "Application.h"

#include "toolbar.h"
#include "game_component.h"

#include "Game.h"

int GameObject::center_x = 320;
int GameObject::center_y = 240;

int Application::main(const std::vector<CL_String> &args){
	CL_ConsoleWindow debug("Debug Console");

	CL_DisplayWindowDescription description;
	description.set_size(CL_Size(640,480), true);
	description.set_title("Hello ClanLib!");
	description.set_allow_resize(false);
	CL_DisplayWindow window(description);


	CL_GUIManager gui(window, "Resources");

	CL_Slot slot_window_close = window.sig_window_close().connect(this, &Application::on_window_close, &gui);

	CL_Rect viewport = window.get_viewport();

	GameComponent game_component(viewport, &gui);

	CL_Rect toolbar_rect = CL_Rect((viewport.right-200)/2, (viewport.bottom-300)/2+200,(viewport.right-150)/2+200,(viewport.bottom-300)/2+300+150 );
	Menu toolbar(toolbar_rect, &game_component,&gui, &window);

	CL_GraphicContext gc = window.get_gc();
	toolbar.add_item(CL_Sprite(gc, "Resources/START.png"), CL_Sprite(gc, "Resources/STARTc.png"), CL_Sprite(gc, "Resources/START.png"));
	toolbar.add_item(CL_Sprite(gc, "Resources/EXIT.png"), CL_Sprite(gc, "Resources/EXITc.png"), CL_Sprite(gc, "Resources/EXIT.png"));

	do{
		gui.exec();
	}while(gui.get_exit_code() != 0);

	return 0;
}

void Application::on_window_close(CL_GUIManager *gui)
{
	gui->exit_with_code(0);
}
